﻿/**
 * ...
 * @author waneck
 */

package asc.io;
import asc.io.File;

class FileOutput extends haxe.io.Output
{

	var file:FileHandle;
	
	public function new(f) 
	{
		file = f;
	}
	
	override public function writeByte(n:Int)
	{
		if (!file.writeByte(n))
			throw haxe.io.Error.Custom("See application.onStatus()");
	}
	
	override public function flush()
	{
		if (!file.flush())
			throw haxe.io.Error.Custom("See application.onStatus()");
	}
	
	override public function close()
	{
		file.close();
	}
	
	public function seek(p:Int, pos:FileSeek)
	{
		var finalpos =
		switch(pos)
		{
			case SeekBegin:
				-file.position + p;
			case SeekCur:
				p;
			case SeekEnd:
				(file.length - file.position) + p;
		}
		
		file.seek(finalpos);
	}
	
	public function tell():Int
	{
		return file.position;
	}
}